{[{define "system/user/index.html"}]}

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <link rel="stylesheet" href="/static/plugs/lay-module/layuimini/layuimini.css" media="all">
    <link rel="stylesheet" href="/static/plugs/lay-module/layuimini/themes/default.css" media="all">
    <style>
        .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>
<body>

<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">ID</label>
                            <div class="layui-input-inline">
                                <input type="int" name="id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">注册类型：</label>
                            <div class="layui-input-inline">
                                <select class="layui-select" name="type">
                                    <option value="100">全部</option>
                                    <option value="111" >游客</option>
                                    <option value="1" >微信</option>
                                    <option value="2" >手机</option>
                                    <option value="3" >一键登录</option>
                                    <option value="4" >苹果登录</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>



        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">详情</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script type="text/html" id="statusSwitch">
    <!--0:禁用; 1:启用 -->
    <!--0:禁用; 1:启用 -->
    {{# if (d.status == 1) { }}
    <input type="checkbox" name="status" id="{{d.id}}" value="{{d.status}}" lay-skin="switch" lay-text="禁用|启用" lay-filter="statusDemo" checked >
    {{# } else { }}
    <input type="checkbox" name="status" id="{{d.id}}" value="{{d.status}}" lay-skin="switch" lay-text="禁用|启用" lay-filter="statusDemo" >
    {{# } }}
</script>
<script src="/static/layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/layuimini/js/lay-config.js" charset="utf-8"></script>
<script src="/static/admin/js/jquery-2.0.3.min.js"></script>
<script src="/static/admin/emoji.js"></script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#time'
            , type: 'datetime'
            , range: '/'
            , format: 'yyyy-M-d H:m:s'
        });
    });
    layui.use(['form', 'table','tree','sh'], function () {
        var _$ = layui.jquery,
            form = layui.form,
            table = layui.table,
            sh = layui.sh;

        form.on('switch(statusDemo)', function (obj) {
            var id=this.id;
            var status=0;
            if(obj.elem.checked){ status=1}
            sh.request.get(
                {
                    url: '/user/user/status',
                    data: {id: id,status:status },
                }, function (res) {
                      sh.msg.success('操作成功');
                }
            );
        });

        var renderTable = function () {
            table.render({
                elem: '#currentTableId',
                url: '/user/user/list',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    /* {type: "checkbox", width: 50},*/
                    {field: 'id', title: 'ID', sort: true, width: 88},
                    {
                        field: 'type', align: 'center', width: 100, templet: function (d) {
                            if (d.type == 0) {
                                return '<span class="layui-badge-rim">游客</span>';
                            }
                            if (d.type == 1) {
                                return '<span class="layui-badge-rim">微信</span>';
                            }
                            if (d.type == 2) {
                                return '<span class="layui-badge-rim">手机</span>';
                            }
                            if (d.type == 3) {
                                return '<span class="layui-badge-rim">一键登录</span>';
                            }
                            if (d.type == 4) {
                                return '<span class="layui-badge-rim">苹果登录</span>';
                            }
                        }, title: '类型'
                    },
                    {field: 'name',  title: '昵称',templet:function(d){
                        return '<span class="emoji">'+d.name+'</span>';
                        }},
                    {field: 'phone',  title: '手机号', align: 'center',templet:function(d){
                        return d.phone == '' ? '-' : d.phone;
                        }},
                    {field: 'head_url',  title: '头像', align: 'center', width: 100, templet: function (d) {
                            return sh.image(d.head_url,'head_url');
                      }
                     },
                    {field: 'status', title: '状态', align: 'center', templet: '#statusSwitch', unresize: true},
                    {field: 'expiration_time', title: 'vip过期时间', minWidth: 160,align: 'center',templet:function (d) {
                            return d.expiration_time == 0 ? '-' : sh.time(d.expiration_time);
                        }},
                    {field: 'add_time', title: '注册时间', minWidth: 160,align: 'center',templet:function (d) {
                            return sh.time(d.add_time);
                        }},
                    {templet: '#currentTableBar', width: 120, align: 'center', title: '操作'}

                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line',
                done:function(){
                    // 延迟300ms处理表情符号
                    setTimeout(function () {
                        $('.emoji').each(function (i,v) {
                            Emoji.emoji(v)
                        });
                    },300);
                }
            });
        }

        renderTable();
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {

            var param = data.field;
            /*var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            })*/;
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    id:param.id,
                    name:param.name,
                    is_vip:param.is_vip,
                    phone:param.phone,
                    type:param.type,
                    register_source:param.register_source,
                    time:param.time,
                    fromapp:param.fromapp
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    skin:'layui-layer-rim',
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/user/user/add',
                });
                _$(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    skin:'layui-layer-rim',
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/user/user/edit?id='+data.id,
                });
                _$(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                id = data.id;
                layer.confirm('真的删除行么 id:'+id, function (index) {

                    sh.request.get(
                        {
                            url: '/user/user/del',
                            data: {id: id},
                        }, function (res) {
                            sh.msg.success('操作成功', function () {
                                renderTable();
                            });
                        }
                    );
                    layer.close(index);
                });
            }else if(obj.event === 'auth'){
                var index = layer.open({
                    title: '权限',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    skin:'layui-layer-rim',
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/user/user/auth?id='+data.id,
                });
                _$(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });

    });

</script>
</body>
</html>
{[{end}]}